<?php
	session_start(); 
	include('user_type/system.php');
	include('access/login_functions.php');
	$_SESSION['restricted'] = false;
?>
<?php
	// retrieve CID from address bar
	$cid = intval($_GET['CID']);
	if (!empty($cid))
	{
		// open databasse
		include('access/opendb.php');
		
		// retrieve the filename
		$query = mysql_query("SELECT * FROM images_table WHERE CID=$cid");
		$entry = mysql_fetch_array($query);
		$filename = $entry['Filename'];
		$title = $entry['Title'];
		// retrieve the author
		$uid = intval($entry['UID']);
		$query = mysql_query("SELECT * FROM user_table WHERE UID=$uid");
		$entry = mysql_fetch_array($query);
		$username = $entry['Username'];
		
		//update pageviews
		mysql_query("UPDATE images_table SET pageviews = pageviews+1 WHERE CID=$cid")or die("Page views could not be updated. ".mysql_error());
		// close database
		include('access/closedb.php');
	}	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>	
	<link rel="stylesheet" type="text/css" href="style_new.css">
	<title>Images - Result</title>
 </head>
<body>

<div class="above_body"> <!-- closing tag is in template navbar -->
	<div id="header" class="floatcontainer doc_header">
		<div><a name="top" href="home.php" class="logo-image"><img src="images\QUESTwtrl2.png"  title=""></a></div>
			<div id="toplinks" class="toplinks">
			
				<ul class="nouser">
				
					<?php if (!isset($_SESSION['user'])) echo "<li><a href=\"register.php\" rel=\"nofollow\">Register</a></li>"; ?>
				
					<li>
					
					<form id="navbar_loginform" action="access/login.php" method="post" >
					<input type="hidden" name="currentPage" value="<?php echo System::curPageName(); ?>" />
						<fieldset id="logindetails" class="logindetails">
							<div>
								<div>
							
							<?php // check if user is logged in
							if(isset($_SESSION['user']))
							{	$user = $_SESSION['user'];
								$_SESSION['curPage'] = System::curPageName(); 
								// if so, display username with tools
								echo "<div style=\"font-size: 16px; font-weight: bold;\">";
								echo "Welcome, $user <br />";
								echo "<a href=\"access/logout.php\">Log Out</a>";
								echo "<a href=\"userTools.php\">myTools</a>";
								echo "<a href=\"userInfo.php\">myProfile</a>";
								
								echo "</div>";
							}
							else
							{	// otherwise, display login form
								echo "<input type=\"text\" class=\"textbox default-value\" name=\"user\" id=\"navbar_username\" size=\"10\" tabindex=\"101\" value=\"Username\"> ";
								echo "<input type=\"password\" class=\"textbox default-value\" tabindex=\"102\" name=\"pass\" id=\"navbar_password_hint\" size=\"10\" value=\"Password\" style=\"display: inline; \"> ";
								echo "<input type=\"submit\" class=\"loginbutton\" tabindex=\"104\" value=\"Log in\" title=\"Enter your username and password in the boxes provided to login.\" accesskey=\"s\">";
							}
						?>
					</form>
					</li>
				</ul>
			</div>
	</div> 
	<div id="navbar" class="navbar">

		<ul id="navtabs" class="navtabs floatcontainer">					
		</ul>
	</div>
</div><!-- closing div for above_body-->
 
<div class="article_block">

	<h2 class="blockhead"></h2>
		<div class="article">
		
		<?php
			echo "<div style=\"text-align: center;\">";
			echo "<img src=\"$filename\" alt=\"$title\" /><br />";
			echo "<h2>$title</h2><br />";
			echo "</div>";
			echo "<hr />";
			echo "<b>Author:</b> $username <a href=\"complaints.php?UID=$uid\">[Complain about this user!]</a>";
		?>

</div>
<br /><br />
<div class="article_block">
		<h2 class="blockhead"></h2>
		<div class="article">
		<h3>Feedback</h3>
		<form action="process/processFeedback.php" method="POST">
			<input type="hidden" name="pageID" value="<?php $_GET['CID']; ?>" />
			<div class="blockrow">
				<textarea rows="5" cols="135" name="feedback"></textarea>
			</div>
			<div class="blockrow" >
				<input type="submit" class="button" value="Submit Feedback!">
			</div>
		</form>
		<br />
		<?php
			if ($_SESSION['user'])
				echo "<a href=\"complaints.php?CID=" . $_GET['CID'] . "&type=image\">Got a complaint about the image?</a>";
		?>
		</div>

</div>
			
<div id="footer" class="floatcontainer footer">

		<center><a href="">Contact WebMaster</a></center>
		
</div>
 </body></html>